package com.app.controller;

import com.app.bean.vo.ZooReq;
import com.app.common.BaseVo;
import com.app.enums.AnnimalTypeEnum;
import com.app.service.IZooHandle;
import com.app.service.RabbitSender;
import com.app.service.ZooFactory;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.app.common.RabbitConst.DELAY_EXCHANGE;
import static com.app.common.RabbitConst.DELAY_ROUTING_KEY;

/**
 * @author xiaoyu.fang
 * @date 2020/1/6 14:24
 */
@RestController
@RequestMapping("/zoo")
public class ZooController {

    @Autowired
    private ZooFactory zooFactory;

    @Autowired
    private RabbitSender rabbitSender;

    @PostMapping("/quark")
    public BaseVo quark(@RequestBody ZooReq zooReq) {
        IZooHandle zooHandle = zooFactory.getInstance(AnnimalTypeEnum.getByValue(zooReq.getAnnimalTypeEnum()));
        return new BaseVo(zooHandle.quark());
    }

    @PostMapping("/sendDelayMsg")
    public BaseVo sendDelayMsg(@RequestBody Message params) {
        rabbitSender.sendDelayMsg(params, DELAY_EXCHANGE, DELAY_ROUTING_KEY, 10000);
        return new BaseVo();
    }

}

@Data
class Message {
    private String id;

    private String msg;
}
